package com.gary.listDemo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author peng_rui
 * @date 2022/3/15
 */
public class ListExceptionDemo {
    public static void main(String[] args) {
        //非线程安全的
//        ArrayList<String> list = new ArrayList<>();

        //CopyOnWriteArrayList
        CopyOnWriteArrayList<Object> list = new CopyOnWriteArrayList<>();

        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        for (Object o : list) {
            System.out.println(o);
        }
//        for (int i = 0; i < 30; i++) {
//            new Thread(() -> {
//                //添加
//                list.add(UUID.randomUUID().toString().substring(0, 8));
////                try {
////                    Thread.sleep(5000);
////                } catch (InterruptedException e) {
////                    e.printStackTrace();
////                }
//                //读取
////                System.out.println(list);
//            }).start();
//            try {
//                Thread.sleep(500);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//            System.out.println(list);
//        }
    }
}
